package com.example.test;

public class AllSort {
    public static void main(String[] args) {
        int[] arrs={1,2,3};
        prem(arrs,0,arrs.length-1);
    }

    private static void prem(int[] arrs, int start, int end) {
        if(start==end){
            for (int i=0;i<=end;i++){
                System.out.print(arrs[i]+"");
            }
            System.out.println("------------------------");
        }else{
            for (int i = start; i <= end; i++) {
                int temp = arrs[start];// 交换数组第一个元素与后续的元素
                arrs[start] = arrs[i];
                arrs[i] = temp;
                prem(arrs, start + 1, end);// 后续元素递归全排列
                temp = arrs[start];// 将交换后的数组还原
                arrs[start] = arrs[i];
                arrs[i] = temp;
            }
        }
    }
}
